<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
   
  <meta name="keywords" content="Java Python" />
   
  <meta name="description" content="From Zero to Hero" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    计算机组成原理-03-校验码 |  朱酱酱的学习博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="朱酱酱的学习博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-Compute_Organization/计组-03-校验码" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  计算机组成原理-03-校验码
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2021/03/26/Compute_Organization/%E8%AE%A1%E7%BB%84-03-%E6%A0%A1%E9%AA%8C%E7%A0%81/" class="article-date">
  <time datetime="2021-03-26T03:02:24.000Z" itemprop="datePublished">2021-03-26</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.2k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">7分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="计算机组成原理-03-校验码"><a href="#计算机组成原理-03-校验码" class="headerlink" title="计算机组成原理-03-校验码"></a>计算机组成原理-03-校验码</h2><h2 id="1-校验码概述"><a href="#1-校验码概述" class="headerlink" title="1. 校验码概述"></a>1. 校验码概述</h2><ul>
<li><p>校验码：指能够<code>发现</code>或能够<code>自动纠正错误</code>的数据编码，也称检错纠错编码。</p>
</li>
<li><p>实现原理：通过加一<code>冗余码</code>，来检验或纠错编码</p>
</li>
<li><p>码距：简单来说就是两个二进制数比较，在同一数位的地方，数位值不同的个数有多少个，即码距，也称海明距离；</p>
</li>
<li><p>两种方法计算码距。比如0100和1111<br><code>直接观察法</code>：可以看出，有3个数位值不同，所以码距为3.<br><code>异或计算法</code>：0100⊕1111=1011 ，结果为1011，里面有几个1就代表有多少个数位值不同，即码距是多少，这里码距是3。</p>
</li>
</ul>
<a id="more"></a>



<h2 id="2-奇偶校验码"><a href="#2-奇偶校验码" class="headerlink" title="2. 奇偶校验码"></a>2. 奇偶校验码</h2><ul>
<li>实现原理： 在原编码中加一个校验位，则<code>原编码就变成了校验码</code>，它的码距为2，可以检查出奇数位错误，但不能检查出偶数位错误，增加的冗余位为奇偶校验位，一般校验位设置在原编码的最左边或最右边。</li>
<li>奇校验码：整个校验码（信息位+校验位）中1的个数位奇数</li>
<li>偶校验码：整个校验码（信息位+校验位）中1的个数位偶数</li>
</ul>
<h3 id="2-1-奇校验"><a href="#2-1-奇校验" class="headerlink" title="2.1 奇校验"></a>2.1 奇校验</h3><p><strong>如何检测出错误？</strong></p>
<ul>
<li>首先在计算机中，我们<strong>就要约定好，数据是采用奇校验还是偶校验</strong>，下面分奇校验和偶校验来说明一下奇偶校验如何检查在计算机传输数据的过程中数据是否正确。</li>
<li>假设我们的原始编码是<code>10110111</code>，因为我们规定计算机采用<code>奇校验</code>，所以我们在原编码最左边多加了一个校验位，并置为1，那么原编码就变成了奇校验码，有奇数（7）个1。<ul>
<li><code>传输过程中奇数个数据改变</code>：在传输过程中有<code>奇数个数位值发生了改变</code>，那么我们通过<code>奇校验运算</code>，可以发现现在变成了6个1，和奇校验码相比有3个数位值发生了改变，奇校验码不再有奇数个1，而是变成了偶数个1，可以判断我们的数据发生了改变，可以检查出错误。</li>
<li><code>传输过程中有偶数个数据改变</code>：在传输过程中有<code>偶数个数位值发生了改变</code>，那么我们通过<code>奇校验运算</code>，都是奇数，这时我们便无法通过奇校验运算判断数据是否发生了改变，<code>即无法检查出偶数个错误</code>。</li>
</ul>
</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210326-093122129.png" alt="mark"></p>
<h3 id="2-2-偶校验"><a href="#2-2-偶校验" class="headerlink" title="2.2 偶校验"></a>2.2 偶校验</h3><ul>
<li>假设我们的原始编码是<code>10110111</code>，因为我们规定计算机采用<code>偶校验</code>，所以我们在原编码最左边多加了一个校验位，并置为0，那么原编码就变成了偶校验码，有偶数（6）个1。<ul>
<li><code>传输过程中奇数个数据改变</code>：在传输过程中有<code>奇数个数位值发生了改变</code>，那么我们通过<code>偶校验运算</code>，可以发现现在变成了5个1，和偶校验码相比有3个数位值发生了改变，偶校验码不再有偶数个1，而是变成了奇数个1，可以判断我们的数据发生了改变，可以检查出错误。</li>
<li><code>传输过程中有偶数个数据改变</code>：在传输过程中有<code>偶数个数位值发生了改变</code>，那么我们通过<code>偶校验运算</code>，可以发现现在变成了6个1，和原偶校验码6个1一样，都是偶数，这时我们便无法通过偶校验运算判断数据是否发生了改变，<code>即无法检查出偶数个错误</code>。</li>
</ul>
</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210326-093311353.png" alt="mark"></p>
<h3 id="2-3-小结"><a href="#2-3-小结" class="headerlink" title="2.3 小结"></a>2.3 小结</h3><ul>
<li>通过上述奇偶校验两种方式校验数据，<strong>可以比较得出奇偶校验可以检测出奇数个错误而无法检查出偶数个错误，也无法纠正错误，无法定位错误位置。</strong></li>
</ul>
<h2 id="3-汉明校验码"><a href="#3-汉明校验码" class="headerlink" title="3. 汉明校验码"></a>3. 汉明校验码</h2><ul>
<li>一种多重奇偶校验码。</li>
<li><strong>实现原理</strong>：在有效信息位中加入几个校验位形成海明码，并把海明码的每一个二进制位分配到几个奇偶校验组中。当某一位出错后，就会引起有关的几个校验位的值发生变化。</li>
<li>特点：可以发现错误，定位错误位置，自动纠正错误。 <code>可以检测双比特错误，但只能纠正单比特错误</code>。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">纠错理论：L-1&#x3D;D+C且D≥C</span><br><span class="line">编码最小码距L越大，其检测错误的位数D越大，纠正错误的位数C也越大，且纠错能力恒小于检错能力</span><br></pre></td></tr></table></figure>



<h3 id="3-1-例题讲解"><a href="#3-1-例题讲解" class="headerlink" title="3.1 例题讲解"></a>3.1 例题讲解</h3><ul>
<li>信息为 n=4 , 校验位 k=3,求1010的海明码</li>
</ul>
<ol>
<li><strong>确定海明码的位数</strong></li>
</ol>
<ul>
<li>根据公式：<strong>2k ≥ n+k+1</strong>（若要检测两位错，则需再增加1位校验位，即k+1位）</li>
<li>海明码位数n+k=7，公式 <strong>2^3 ≥ n+k+1=8</strong>成立，n,k有效。设置变量来表示信息位、校验位、海明码。</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-203146422.png" alt="mark"></p>
<ol start="2">
<li><strong>确定校验位的分布</strong></li>
</ol>
<ul>
<li>规定校验位 pi 在海明位号位 2^(i-1) 的位置上，所以：</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-203249694.png" alt="mark"></p>
<ol start="3">
<li><strong>分组形成校验关系</strong></li>
</ol>
<ul>
<li>每个数据位用多个校验位来检验。</li>
<li>必须满足条件：<code>被校验数据位的海明码位号 = 校验该数据位的各校验位海明位号之和</code>，比如校验D3，它的海明位号H6为6，那么校验它的校验位为P3和P2，因为他们的海明位号H4和H2加起来等于6。（化为二进制的位数）</li>
<li>校验位不需要再被校验</li>
<li>分组关系如图：</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-203511638.png" alt="mark"></p>
<ol start="4">
<li><strong>校验位的取值</strong></li>
</ol>
<ul>
<li>Pi的值 = 第 i 组所有数据位求异或⨁</li>
<li>P1=D1⨁D2⨁D4=0</li>
<li>P2=D1⨁D3⨁D4=1</li>
<li>P3=D2⨁D3⨁D4=0</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-203558634.png" alt="mark"></p>
<ol start="5">
<li><strong>海明码的校验原理</strong></li>
</ol>
<ul>
<li><p>每个校验组分别利用校验位和参与形成该校验位的信息位进行奇偶校验检查，即异或运算⨁，构成k个校验方程。</p>
<ul>
<li>S1=P1⨁D1⨁D2⨁D4</li>
<li>S2=P2⨁D1⨁D3⨁D4</li>
<li>S3=P3⨁D2⨁D3⨁D4</li>
</ul>
</li>
<li><p>若S1S2S3=000,则说明无错，否则说明出错。</p>
</li>
<li><p>这个数的值就是出错的位置，如S1S2S3=001,表示第1位出错，即H1出错，直接将该位取反就可以达到<code>纠错</code>的目的。</p>
</li>
</ul>
<h2 id="4-循环冗余CRC码"><a href="#4-循环冗余CRC码" class="headerlink" title="4. 循环冗余CRC码"></a>4. 循环冗余CRC码</h2><p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-203807533.png" alt="mark"></p>
<ul>
<li>基本思想：校验码中的一种。在K位信息位后拼接R位检验位，组成CRC码，这种编码也称(N,R)码</li>
<li>特点：可以发现错误，定位错误位置，自动纠正错误。<code>可检测出所有奇数位错，所有双比特的错和所有小于、等于校验位长度的突发错</code></li>
</ul>
<ol>
<li><strong>生成多项式</strong></li>
</ol>
<ul>
<li>首先，发送端和接受端会有一个生成多项式G(x)约定,生成多项式G(x)的最高次幂为<code>R</code>。任意一个二进制数码都可用一个系数为0或1的多项式与之对应。比如：二进制数码 1101 对应的G(x)=1<em>X^3+1</em>X^2+0<em>X^1+1</em>X^0= X^3+X^2+1</li>
<li>在发送端，将要传送的K位二进制信息码左移R位，将它与生成多项式G(x)所对应的的二进制数码进行<code>模2除法</code>，产生余数，生成一个R位检验码，并附在信息码后，构成一个新的二进制码（CRC）码，共K+R位。</li>
</ul>
<h3 id="4-1-例题讲解"><a href="#4-1-例题讲解" class="headerlink" title="4.1 例题讲解"></a>4.1 例题讲解</h3><ul>
<li>例题： 设生成多项式G(x)=X^3+X^2+1 ,信息码为 101001 ，求对应的CRC码 。</li>
</ul>
<p><strong>分析</strong></p>
<ul>
<li>分析：校验位长度：R=3 , 信息码长度：K=6 , CRC码长度：N=R+K= 9</li>
<li>生成多项式对应二进制码：1101</li>
</ul>
<ol>
<li><strong>信息码左移R位</strong></li>
</ol>
<ul>
<li>发送端将原信息码左移R位，低位补0：101001 000</li>
</ul>
<ol start="2">
<li><strong>模2除得到余数</strong></li>
</ol>
<ul>
<li>方法：发送端用移位后的信息码 101001000 除以G(x)所对应的二进制数码 1101 求余数，余数除得够就写1，不够就写0，直到余数小于 1101 ，余数即为校验位的数值。</li>
<li>图中即为具体计算步骤，得到最后的结果CRC码为：101001 001，然后发送端将CRC码101001 001发送给接收端。</li>
</ul>
<p><img src="http://zhuuu-bucket.oss-cn-beijing.aliyuncs.com/img/20210327-204223140.png" alt="mark"></p>
<ol start="3">
<li><strong>如何检错和纠错？</strong></li>
</ol>
<ul>
<li><p>接收端收到CRC码后，用生成的CRC码除以生成多项式G(x)所对应的的二进制数码，<strong>若余数为0，则信息码在传输过程中没有产生错误，数据正确。</strong></p>
</li>
<li><p>若接受到的CRC码为<code>C9C8C7C6C5C4C3C2C1= 101001011</code>,除以G(x)所对应的二进制码1101得到余数为010，不为0，说明数据在传输过程中产生错误。<code>010=2（10）</code>说明C2出错，将C2取反即可纠正错误。</p>
</li>
</ul>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://zhuuu.work/2021/03/26/Compute_Organization/%E8%AE%A1%E7%BB%84-03-%E6%A0%A1%E9%AA%8C%E7%A0%81/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80%E7%90%86%E8%AE%BA/" rel="tag">计算机基础理论</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86/" rel="tag">计算机组成原理</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2021/03/26/rabbitMQ/RabbitMQ-06-%E6%A0%B8%E5%BF%83%E7%BB%84%E6%88%90%E9%83%A8%E5%88%86/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            RabbitMQ-06-核心组成部分
          
        </div>
      </a>
    
    
      <a href="/2021/03/25/Compute_Organization/%E8%AE%A1%E7%BB%84-02-%E8%BF%9B%E5%88%B6%E4%B8%8E%E7%BC%96%E7%A0%81/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">计算机组成原理-02-进制与编码</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        notify: false,
        verify: '',
        app_id: '',
        app_key: '',
        path: window.location.pathname,
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
<div class="gitalk" id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.5.0/dist/gitalk.css">


<script src="https://cdn.jsdelivr.net/npm/gitalk@1.5.0/dist/gitalk.min.js"></script>


<script src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>

<script type="text/javascript">
  var gitalk = new Gitalk({
    clientID: 'db188ed8c86dc4b0dbf3',
    clientSecret: 'a58f92160e5a9efd726b7d533000a0737f3e3f3e',
    repo: 'Blog-comments',
    owner: 'Zhuuuuuuuu',
    admin: ['Zhuuuuuuuu'],
    // id: location.pathname,      // Ensure uniqueness and length less than 50
    id: md5(location.pathname),
    distractionFreeMode: false,  // Facebook-like distraction free mode
    pagerDirection: 'last'
  })

  gitalk.render('gitalk-container')
</script>

  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2019-2021
        Zhuuu
      </li>
      <li>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="朱酱酱的学习博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/JVM/">JVM</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/JDK%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/">JDK源码</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/">多线程</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Mysql/">Mysql</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Redis/">Redis</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E8%AE%BE%E8%AE%A1%E8%80%85%E6%A8%A1%E5%BC%8F/">设计模式</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/MyBatis/">MyBatis</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/SpringMVC/">SpringMVC</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Spring/">Spring</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/SpringBoot/">SpringBoot</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">Linux</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Leetcode/">Leetcode</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E5%89%8D%E7%AB%AF/">前端</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/">网络编程</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/photoshop/">photoshop</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="http://smartzhuuu.lofter.com/" target="_blank" rel="noopener">摄影</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['昨夜西风凋碧树。独上高楼，望尽天涯路','衣带渐宽终不悔，为伊消得人憔悴。','众里寻他千百度。蓦然回首，那人却在，灯火阑珊处。'],
    startDelay: 0,
    typeSpeed: 200,
    loop: true,
    backSpeed: 100,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: true
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>



<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>